package com.classichu.jetpacksimple.data.local;

import android.arch.persistence.room.Room;
import android.util.Log;

import com.classichu.jetpacksimple.AppApplication;


public class AppDatabaseManager {
    //===============
    private AppDatabaseManager() {

    }

    public static AppDatabaseManager getInstance() {
        return AppDatabaseManager.Inner.sInstance;
    }

    private static class Inner {
        private static AppDatabaseManager sInstance = new AppDatabaseManager();
    }

    //===============
    private static final String DATABASE_NAME = "news.db";
    private static AppDatabase mAppDatabase;

    // TODO: 2018/7/15 确保实例生成一次
    public AppDatabase getAppDatabase() {
        if (mAppDatabase == null) {
            mAppDatabase = Room.databaseBuilder(AppApplication.getInstance(), AppDatabase.class, DATABASE_NAME)
                    .build();
        }
        Log.d("zfq", "getAppDatabase: " + mAppDatabase);
        return mAppDatabase;
    }

}
